package com.xinbochuang.machine.admin.config;

import io.minio.MinioClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class MinioConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(MinioConfig.class);

    @Autowired
    private MinioData minioData;

    /**
     * 初始化minio客户端,不用每次都初始化
     *
     * @return MinioClient
     * @author 溪云阁
     */
    @Bean
    public MinioClient minioClient() {
        try {
            return new MinioClient(minioData.getEndpoint(), minioData.getAccessKey(), minioData.getSecretKey());
        } catch (final Exception e) {
            LOGGER.error("初始化minio出现异常:{}", e.fillInStackTrace());
            e.printStackTrace();
        }
        return null;
    }
}
